package com.whtq.front.common.model.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.whtq.front.common.basics.WHTQReturnCode;
import lombok.Data;

import java.io.Serializable;

/**
 * Created by
 *
 * @author wmi
 * @date 2021/9/14 - 17:07.
 * @description
 */
@Data
@JsonPropertyOrder(value = {"code", "msg", "data"})//此注解意思为:定义json数据的排序
public class WHTQRes implements Serializable {
    private String code;

    private String msg;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    public WHTQRes() {
    }

    public WHTQRes(WHTQReturnCode whtqReturnCode) {
        this.code = whtqReturnCode.getCode();
        this.msg = whtqReturnCode.getMessage();
    }

    public WHTQRes(WHTQReturnCode whtqReturnCode, Object data) {
        this.code = whtqReturnCode.getCode();
        this.msg = whtqReturnCode.getMessage();
        this.data = data;
    }

    public WHTQRes success() {
        WHTQRes result = new WHTQRes(WHTQReturnCode.SUCCESS);
        return result;
    }

    public static WHTQRes success(Object data) {
        WHTQRes result = new WHTQRes(WHTQReturnCode.SUCCESS, data);
        return result;
    }

    public static WHTQRes failure(String code, String message) {
        WHTQRes result = new WHTQRes();
        result.setCode(code);
        result.setMsg(message);
        return result;
    }

    public static WHTQRes failure(WHTQReturnCode whtqReturnCode) {
        WHTQRes result = new WHTQRes(whtqReturnCode);
        return result;
    }

    public static WHTQRes failure(WHTQReturnCode whtqReturnCode, Object data) {
        WHTQRes result = new WHTQRes(whtqReturnCode, data);
        return result;
    }


    @Override
    public String toString() {
        return "{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
